package cn.com.yusys.yusp.admin.log;

import cn.com.yusys.yusp.admin.domain.AdminSmLog;
import cn.com.yusys.yusp.admin.log.common.AbstractLogProcessor;
import cn.com.yusys.yusp.admin.log.common.CommonLogInfo;
import cn.com.yusys.yusp.admin.repository.mapper.SystemLogMapper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * @Description: 提供构造器接受参数
 * @author: lupan
 * @date: 2018/1/31
 */
public class BusinessLogProcessor extends AbstractLogProcessor {
    
    private static final Logger logger = LoggerFactory.getLogger(BusinessLogProcessor.class);
    
    @Autowired
    private SystemLogMapper systemLogMapper;

    private void addLog(AdminSmLog loginfo) {
        if(StringUtils.isNotEmpty(loginfo.getLogId())){
            loginfo.setLogId(null);
        }
        systemLogMapper.insertSelective(loginfo);
    }

    @Override
    public void process(CommonLogInfo logInfo) {
        logger.debug("线程:{}开始处理日志", Thread.currentThread());
        AdminSmLog adminSmLog = (AdminSmLog) logInfo.getLogInfo();
        addLog(adminSmLog);
        logger.debug("线程:{}结束日志处理", Thread.currentThread());
    }
}